<?php
@session_start();
include_once 'session_var.php';
if($_SESSION['web']!=true) {
		$_SESSION['languaje'] = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"],0,2);
		//header('Location: http://firstclassapartment.com.ar/'.$_SESSION['languaje'].'/book.php');
		header('Location: //localhost/firstclassapartmentscordoba/'.$_SESSION['languaje'].'/book.php');
	}else {
		include("../lang/{$_SESSION['languaje']}.php");
	}

//var_dump($_SESSION['languaje']);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang=<?php echo $_SESSION['languaje'];?>>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta name="description" content=<?php echo $book_description;?>>
		<meta name="author" content="Pulce Web Solutions - www.pulce.com.ar">
		<!--Para que las páginas se muestren correctamente y el zoom funcione bien en los dispositivos móviles-->
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta name="keywords" content="<?php echo $index_keywords;?>">

		<title><?php echo $book_title?></title>

		<?php
			include_once('links.php');
			include_once('function.inc.php');
			include_once('session_var.php');
		?>
		<!--<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.1/themes/base/jquery-ui.css" />-->
		<link href="../css/sunny/jquery-ui-1.10.4.custom.min.css" rel="stylesheet">

		<!--JQUERY-->
		<script src="http://code.jquery.com/jquery-2.1.0.js"></script>
		<!--BOOTSTRAP-->
		<script src="../js/bootstrap.min.js"></script>
		<!--FUNCTIONS-->
		<script src="../js/functions.js"></script>
		<!--JQ-UI-->
		<script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
		<!--DATEPICKER LANGUAJE-->
		<?php if ($_SESSION['languaje']<>"en"){?>
		<script src="../js/datapicker-languajes/jquery.ui.datepicker-<?php echo $_SESSION['languaje'];?>.js"></script>
		<?php } ?>
		<!-- BACKSTRECH -->
		<script src="../js/jquery.backstretch.min.js"></script>
		<!-- DROPDOWN -->
		<script src="../js/dropdown.js"></script>
		<!-- TRANSITION -->
		<script src="../js/transition.js"></script>

		<script type="text/javascript">
			$(document).ready(function(){
				$.datepicker.setDefaults({
				  	showOn: "both",
					<?php if($_SESSION['languaje']=='es'){?>
						dateFormat: "dd/mm/yy",
					<?php }else{?>
					  	dateFormat: "mm/dd/yy",
					<?php }?>
					buttonImage: "../img/symbol/calendar-icon-512x512.png",
					defaultDate: "now",
					maxDate: "+1y",
					minDate: "now"
				});
				$("#checkin").datepicker({
		        	onClose: function (selectedDate) {
		            	if (!isEmpty('checkin')){
		            		var dateMin = $('#checkin').datepicker("getDate");
							var rMin = new Date(dateMin.getFullYear(), dateMin.getMonth(), dateMin.getDate() + 1);
		            		$("#checkout").datepicker("option", "minDate", rMin);
		            		$("#checkout").datepicker( "show" );}
		            }			
				});
				$("#checkout").datepicker({
				});

				$('#box').on('change',function(e){
					if (isSet('div-msg'))
						$('#div-msg').fadeOut();
				});

				/*$('#form-data').on('change',function(e){
					if (isSet('div-msg'))
						$('#div-msg').fadeOut();
				});*/

				//Cargo combo moneda
				g("../ajax.php?"+a('ArmarComboMoneda')+c('table','T_CURRENCY')+c('id','id_currency')+c('value','concat(chr_value,\' - \',chr_description_<?php echo $_SESSION['languaje'];?>)')+c('name','inputCurrency')+c('puntero','3'), 'SelectCurrency' , '' , 'img-loading',true);
				//Cargo combo pais
				g("../ajax.php?"+a('ArmarComboPais')+c('table','T_COUNTRIES')+c('id','id_country')+c('value','chr_name_<?php echo $_SESSION['languaje'];?>')+c('msgSelect','<?php echo $msg_select;?>')+c('name','inputCountry')+c('tabindex','3'), 'SelectCountry' , '' , 'img-loading',true);
				
				//Codigo telefonico
				$('#SelectCountry').change(function() {
					var id = $("#inputCountry").val();
					g("../ajax.php?"+a('returnDialCode')+c('id',id), 'dialingCode' , '' , 'img-loading',true);
					g("../ajax.php?"+a('returnDialCode')+c('id',id), 'dialingOptCode' , '' , 'img-loading',true);
				});

				//Combo Horario
				g("../ajax.php?"+a('armarComboArrive')+c('msgKnow','<?php echo $msg_know;?>')+c('msgNext','<?php echo $msg_next;?>')+c('name','inputArrive')+c('tabindex','8'), 'SelectArrive' , '' , 'img-loading',true);
				

				//Cambio de moneda
				$('#SelectCurrency').change(function(){
					g("../ajax.php"+a('get_rate')+v('inputCurrency'),'book-rates','','img-loading',true);
					g('../ajax.php?'+a('calcPrice')+v('checkin')+v('checkout')+v('guests')+v('inputCurrency'),'pricing', 'div-msg' , 'img-loading',true);
				});

				//Precios
				g("../ajax.php"+a('get_rate')+c('inputCurrency','3'),'book-rates','','img-loading',true);

			});
		</script>
				
	<body>
		<div id="menu_bar">
			<?php include_once('menu_bar.php');?>
		</div>
		<div class="container">
			
			<div id="backstretch">
				<script>
					$.backstretch([
					"../img/bkbook.jpg"
					],{duration: 5000,fade:750});
				</script>
			</div>
			<div class="row">
				<div class="col-xs-8">
					<div id="box" class="box-central pos-book">
						<div class="row">
							<div class="col-xs-6">
								<h1><?php echo $book_box_main_title;?></h1>
							</div>
							<div class="col-xs-1">
								<div id="img-loading"></div>
							</div>
							<div class="col-xs-5 right">
								<button id="btn-updbooking" type="button" class="btn btn-info" onclick="window.open('bookupd.php','_self');"><?php echo $book_updbooking;?></button>
							</div>
						</div>
						<!-- STEP1 -->
						<div id="step1">
							<h2>
								<?php echo $book_box_step1;?>
							</h2>
							<p>
								<?php echo $book_avalibility;?>
							</p>
							<div class="row margin-top-1em">
								<div class="form-group">
									<label for="inputCheckIn" class="col-xs-2 control-label label-custom"><?php echo $book_check_in;?></label>
									<div class="col-xs-3">
										<input id="checkin" type="text">
									</div>
									<label for="inputCheckOut" class="col-xs-1 control-label label-custom"><?php echo $book_check_out;?></label>
									<div class="col-xs-3">
										<input id="checkout" type="text" id="checkout">
									</div>
									<div class="col-xs-3"><label class="control-label label-custom"><?php echo $book_guests;?></label>
										<?php selectGuests();?>
									</div>
								</div>
							</div>
							<div id="step1-to2" style="text-align: right;">
								<button id="btn-toStep2" type="button" class="btn btn-warning btn-custom"><?php echo $book_step2;?></button>
							</div>

							<script type="text/javascript">								
								$('#btn-toStep2').on('click',function(e){

									/*if (isSet('div-msg')){
										finish('div-msg');
										$('#div-msg').fadeOut();
									}*/

									if (isEmpty('checkin') || isEmpty('checkout')){
									   	showMsg('div-msg','<?php echo $book_msg_dates1;?>','a');
									   	return;
									}
									var guests=parseInt($('#guests').val());

									//Buscar disponibilidad en base de datos
									g("../ajax.php?"+a('check_availability')+v('checkin')+v('checkout')+v('guests'), 'result' , 'div-msg' , 'img-loading',true);
								});						
							</script>

						</div>
						<!-- STEP2 -->
						<div id="step2" style="display: none;">
							<h2>
								<?php echo $book_box_step2;?>
							</h2>
							<p>
								<?php echo $book_data;?>
							</p>
							<div id="form-data">
								<form id="book-data">
									<div class="row margin-top-1em">
										<div class="form-group">
											<label for="inputName" class="col-xs-2 control-label label-custom"><?php echo $book_data_name.' *';?></label>
										    <div class="col-xs-4">
										    	<input type="text" class="form-control" id="inputName" placeholder="<?php echo $book_data_name_h;?>" tabindex="1">
										    </div>
											<label for="inputLastName" class="col-xs-2 control-label label-custom"><?php echo $book_data_last_name.' *';?></label>
										    <div class="col-xs-4">
										    	<input type="text" class="form-control" id="inputLastName" placeholder="<?php echo $book_data_last_name_h;?>" tabindex="2">
										    </div>
									  </div>
									</div>
									<div class="row margin-top-1em">
										<div class="form-group">
											<label for="inputCountry" class="col-xs-2 control-label label-custom"><?php echo $book_data_country.' *';?></label>
										    <div class="col-xs-10">
										    	<div id="SelectCountry">
										    	</div>
										    </div>
									  </div>
									</div>
									<div class="row margin-top-1em">
										<div class="form-group">
											<label for="inputEmail" class="col-xs-2 control-label label-custom"><?php echo $book_data_email.' *';?></label>
										    <div class="col-xs-4">
												<input id="inputEmail" type="email" class="form-control" placeholder="<?php echo $book_data_email_h;?>"  tabindex="4">
										    </div>
										    <label for="inputPhone" class="col-xs-2 control-label label-custom"><?php echo $book_data_phone.' *';?></label>
										    <div class="col-xs-4">
										    	<div class="input-group">
												  <span id="dialingCode" class="input-group-addon"></span>
												  <input id="inputPhone" type="text" class="form-control" placeholder="<?php echo $book_data_phone_h;?>" tabindex="6">
												</div>
										    </div>
									  </div>
									</div>
									<div class="row margin-top-1em">
										<div class="form-group">
											<label for="inputConfirmEmail" onpaste="return false" class="col-xs-2 control-label label-custom"><?php echo $book_data_conf_email.' *';?></label>
										    <div class="col-xs-4">
												<input id="inputConfirmEmail" type="email" class="form-control" placeholder="<?php echo $book_data_conf_email_h;?>" tabindex="5">
										    </div>
										    <label for="inputOptPhone" class="col-xs-2 control-label label-custom"><?php echo $book_data_opt_phone;?></label>
										    <div class="col-xs-4">
										    	<div class="input-group">
												  <span id="dialingOptCode" class="input-group-addon"></span>
												  <input id="inputOptPhone" type="text" class="form-control" placeholder="<?php echo $book_data_opt_phone_h;?>" tabindex="7">
												</div>
										    </div>
									  	</div>
									</div>
									<div class="row margin-top-1em">
										<div class="row">
											<div class="form-group">
												<label for="inputArrive" class="col-xs-4 col-xs-offset-1 control-label label-custom"><?php echo $book_data_arrive;?></label>
											    <div class="col-xs-4">
											    	<div id="SelectArrive">
												   	</div>
											    </div>
											</div>
										</div>
									</div>
									<div class="row margin-top-1em">
										<div class="form-group">
											<label for="inputRequest" class="col-xs-2 control-label label-custom"><?php echo $book_data_request;?></label>
										    <div class="col-xs-10">
										    	<textarea class="form-control" id="inputRequest" placeholder="<?php echo $book_data_request_h;?>" tabindex="9"></textarea>
										    </div>
									  </div>
									</div>
								</form>
							</div>
							<div class="row">
								<div class="col-xs-6">
									<div id="step2-to1" style="text-align: left;">
										<button id="btn-toStep1" type="button" class="btn btn-warning btn-custom"><?php echo $book_back_step1;?></button>
									</div>
								</div>
								<div class="col-xs-6">
									<div id="step2-to3" style="text-align: right;">
										<button id="btn-toStep3" type="button" class="btn btn-warning btn-custom"><?php echo $book_step3;?></button>
									</div>
								</div>
							</div>
							<script type="text/javascript">
								$('#btn-toStep1').on('click',function(e){
										/*if (hasMsg('div-msg'))
											$('#div-msg').fadeOut();*/
										$('#step1').toggle(300);
										$('#step2').toggle(300);
								});

								$('#btn-toStep3').on('click',function(e){

									/*if (isSet('div-msg')){
										finish('div-msg');
										$('#div-msg').fadeOut();
									}*/

									//Verifico datos
									g('../ajax.php?'+a('verifBookingData')+v('inputName')+v('inputLastName')+v('inputCountry')+v('inputEmail')+v('inputConfirmEmail')+v('inputPhone'),'', 'div-msg' , 'img-loading',false);
									if (hasMsg('div-msg'))
										return;
									g('../ajax.php?'+a('ShowConfirmBook')+v('checkin')+v('checkout')+v('guests')+v('inputName')+v('inputLastName')+v('inputCountry')+v('inputEmail')+v('inputConfirmEmail')+v('inputPhone')+v('inputOptPhone')+'&inputArrive='+$("#inputArrive option:selected").html()+v('inputRequest'),'resumen', 'div-msg' , 'img-loading',true);
									g('../ajax.php?'+a('calcPrice')+v('checkin')+v('checkout')+v('guests')+v('inputCurrency'),'pricing', 'div-msg' , 'img-loading',true);
									$('#step2').toggle(300);
									$('#step3').toggle(300);									
								});					
							</script>
						</div>
						<!-- STEP3 -->
						<div id="step3" style="display: none;">
							<h2>
								<?php echo $book_box_step3;?>
							</h2>
							<p>
								<?php echo $book_confirmation;?>
							</p>
							<div class="row margin-top-1em box-no-border">
								<div id="resumen" class="col-xs-8 box-border-right">
								</div>
								<div id="pricing" class="col-xs-4">
								</div>
							</div>
							<div class="row">
								<div class="col-xs-6">
									<div id="step2-to1" style="text-align: left;">
										<button id="btn-backStep2" type="button" class="btn btn-warning btn-custom"><?php echo $book_back_step2;?></button>
									</div>
								</div>
								<div class="col-xs-6">
									<div id="step2-to3" style="text-align: right;">
										<button id="btn-confirm" type="button" class="btn btn-success btn-custom"><?php echo $book_confirm;?></button>
									</div>
								</div>
							</div>
							<script type="text/javascript">
								$('#btn-backStep2').on('click',function(e){
									$('#step2').toggle(300);
									$('#step3').toggle(300);
								});	
								$('#btn-confirm').on('click',function(e){									
									//Buscar disponibilidad en base de datos
									g("../ajax.php?"+a('check_availability')+v('checkin')+v('checkout')+v('guests'), '' , 'div-msg' , 'img-loading',false);
									if (hasMsg('div-msg'))
										return;
									g('../ajax.php?'+a('verifBookingData')+v('inputName')+v('inputLastName')+v('inputCountry')+v('inputEmail')+v('inputConfirmEmail')+v('inputPhone'),'', 'div-msg' , 'img-loading',false);
									if (hasMsg('div-msg'))
										return;
									g('../ajax.php?'+a('ConfirmBook')+v('checkin')+v('checkout')+v('guests')+v('inputName')+v('inputLastName')+v('inputCountry')+v('inputEmail')+v('inputConfirmEmail')+v('inputPhone')+v('inputOptPhone')+'&arrive='+$("#inputArrive option:selected").html()+v('inputArrive')+v('inputRequest')+v('inputCurrency'),'result', 'div-msg' , 'img-loading',true);
									
									$('#step3').toggle(300);
								});	
							</script>
						</div>
						<!-- CONFIRMATION -->
						<div id="confirmation1" style="display: none;"></div>
						<div id="confirmation2" style="display: none;"></div>
						
						<div id="div-msg" style="display: none">
						</div>
						
						<div id="result" style="display: none;">
							
						</div>

					</div>
				</div>
				<div class="col-xs-4">
					<div id="box-rates" class="box-central">
						<div class="row">
							<div class="col-xs-4">
								<h1>
									<?php echo $book_box_rates_main_title;?>
								</h1>
							</div>
							<div class="col-xs-8">
								<div id="SelectCurrency">
								</div>
							</div>
						</div>
						<div id="book-rates">
						</div>
					</div>
					<div id="box-conditions" class="box-central">
						<h1>
							<?php echo $book_box_cond_main_title;?>
						</h1>
						<div class="row">
							<div class="col-xs-2">
								<div class="icons-servicios">
									<img src="../img/icons/glyphicons_054_clock.png" class="img-icons-servicios"/>
								</div>
							</div>
							<div class="col-xs-10">
								<p class="text-apart">
									<?php echo $book_cond_reservation;?>
								</p>
							</div>
						</div>
						<div class="row margin-top-1em">
							<div class="col-xs-2">
								<div class="icons-servicios">
									<img src="../img/icons/glyphicons_152_check.png" class="img-icons-servicios"/>
								</div>
							</div>
							<div class="col-xs-10">
								<p class="text-apart">
									<?php echo $book_cond_deposit;?>
								</p>
							</div>
						</div>
						<?php if($_SESSION['no_reembolsable']==1){?>
						<div class="row margin-top-1em">
							<div class="col-xs-2">
								<div class="icons-servicios">
									<img src="../img/icons/glyphicons_037_coins.png" class="img-icons-servicios"/>
								</div>
							</div>
							<div class="col-xs-10">
								<p class="text-apart">
									<?php echo $book_cond_refund;?>
								</p>
							</div>
						</div>
						<?php } ?>
					</div>
				</div>
			</div>
		</div>
		<div id="footer">
			<?php include("footer.php");?>
		</div>
	</body>
</html>